var brandList, pbcList;

$(function () {

	   
    
  //营销状态
    $("[name='btn_is_act']").click(function () {
        var id = $(this).data("id");
        var type = $(this).data("type");
        var qrtype = $(this).data("qrtype");
//        console.log(qrtype);
        if (qrtype == 2 ){
        	 bootbox.balert("普通码箱码不参与营销！");
             return;
        }
        bootbox.bconfirm("确定更改营销状态？", function (re) {
            if (re) {
            	jQuery.ajax({
                    type:'post',
                    url:'/qrcodeproduct/upact',
                    data:{'id':id,'type':type},
                    dataType:'json',
                    cache:false,
                    success:function(data){
                    	
                    	tipper.success("操作成功！");
                    	window.location.href=window.location.href; 
                    	window.location.reload; 
                    },
                    error:function(){
                    	tipper.danger("解绑失败，请重试");
                    }
               });
             
            }
        });
    });
    
    
   
    
  //数据导出
    $("[name='btn_qrcodeproduct_export1']").click(function () {
    	var prodBillcode = $("[name='prodBillcode']").val();
        var prodBatchno = $("[name='prodBatchno']").val();
        var groupcode = $("[name='groupcode']").val();
        var outerboxId = $("[name='outerboxId']").val();
        var qrcodeId = $("[name='qrcodeId']").val();
        
        //有数据时才能导出
        if($("#resultTotal_hidden").val() != 0){
        	bootbox.bconfirm("确定是否导出？", function (re) {
                if (re) {
                	 var url="/qrcodeautoproductdetail/export?prodBillcode="+prodBillcode+"&prodBatchno="+prodBatchno+"&groupcode="+groupcode
                	 +"&outerboxId="+outerboxId+"&qrcodeId="+qrcodeId;
                     window.open(url);
                }
            });
        }else{
        	bootbox.balert("没有数据，无法导出!");
        }
    });

    //===================以下为公共方法============================

    /**
     *转换long值为日期字符串
     * @param l long值
     * @param pattern 格式字符串,例如：yyyy-MM-dd hh:mm:ss
     * @return 符合要求的日期字符串
     */

    function getFormatDateByLong(l, pattern) {
        return getFormatDate(new Date(l), pattern);
    }

    function getFormatDate(date, pattern) {
        if (date == undefined) {
            date = new Date();
        }
        if (pattern == undefined) {
            pattern = "yyyy-MM-dd hh:mm:ss";
        }
        return date.format(pattern);
    }
    //扩展Date的format方法
    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S": this.getMilliseconds()
        }
        if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            }
        }
        return format;
    }


});
